package com.example.spzs.Task;

import com.alibaba.fastjson.JSONObject;
import com.example.spzs.pojo.goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class getgoodsTask {
    @Autowired
    private com.example.spzs.util.getgoods getgoods;

    public goods getgoods(String url){
        String html = getgoods.execute(url);
        System.out.println(html);
        return  parse(html);
    }
    public goods parse(String html){
        goods goods = new goods();
        JSONObject json = JSONObject.parseObject(html);
        String data = json.getString("data");
        if (data!=null){
            String name = JSONObject.parseObject(data).getString("name");
            Integer price = JSONObject.parseObject(data).getInteger("price");
            Integer market_price = JSONObject.parseObject(data).getInteger("market_price");
            String spec = JSONObject.parseObject(data).getString("spec");
            String sub_title = JSONObject.parseObject(data).getString("sub_title");
            goods.setName(name);
            goods.setPrice(price);
            goods.setMarket_price(market_price);
            goods.setSpec(spec);
            goods.setSub_title(sub_title);
        }
        return goods;
    }
}
